home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / util / cli / nuke10.lha / nuke10 / nuke.c next >
Encoding:
C/C++ Source or Header  |  1995-03-29  |  1.5 KB  |  66 lines

  1. /*
  2.  * nuke.c
  3.  *
  4.  * this is a secure file deletion command
  5.  * written by Giovanni Gigante, 4 march 1994, V 1.0
  6.  * this code is freeware
  7.  *
  8.  * CAUTION: read the enclosed document before using.
  9.  *
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #define N_PASSES 3
  16. #define EXIT_BAD 20
  17. #define EXIT_WARN 10
  18.  
  19. void main(int argc, char *argv[]) {
  20.     
  21.     FILE *fp;
  22.     long length;
  23.     int i,j;
  24.     const char version[]="$VER: 1.0 950304";
  25.         const int fill[N_PASSES]={0x00,0xff,0x00};
  26.  
  27.     /* check CLI syntax */
  28.     if (argc != 2) {
  29.         fprintf(stderr,"Nuke 1.0 by Giovanni Gigante\n");
  30.                 fprintf(stderr,"Usage: %s <filename>\n",argv[0]);
  31.         exit(EXIT_BAD);
  32.     }
  33.     
  34.     /* open file and get its length*/
  35.     if(!(fp=fopen(argv[1],"r"))) {
  36.         fprintf(stderr,"Cannot open %s\n",argv[1]);
  37.         exit(EXIT_BAD);
  38.     }
  39.     if(fseek(fp,0,SEEK_END)) exit(EXIT_BAD);
  40.     length=ftell(fp);
  41.     
  42.     /* overwrite file several times */
  43.         for(j=0; j<N_PASSES; j++) {
  44.             if(!(fp=freopen(argv[1],"w",fp))) {
  45.                 fprintf(stderr,"Cannot reopen %s at pass %d\n",argv[1],j);
  46.                 exit(EXIT_BAD);
  47.             }
  48.             for(i=0; i<=length; i++) {
  49.                         if (fputc(fill[j],fp)==EOF) {
  50.                         fprintf(stderr,"Cannot write to %s\n",argv[1]);
  51.                         exit(EXIT_BAD);
  52.                         }
  53.                 }
  54.                 fclose(fp);
  55.         }
  56.  
  57.     /* delete file */
  58.     if(remove(argv[1])) {
  59.         fprintf(stderr,"%s  overwritten, but cannot be deleted\n",argv[1]);
  60.         exit(EXIT_WARN);
  61.     }
  62.  
  63.     fprintf(stderr,"%s  Nuked.\n",argv[1]);
  64. } /*main*/
  65.  
  66.